﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Microsoft.SqlServer.Management.Smo;
using SQLServices.Repository;

namespace SQLRunnerSMO
{
    public class Util : ISQLServerFinder
    {
        #region Implementation of ISQLServerFinder

        /// <summary>
        /// This helper method returns a list of SQL Servers
        /// available at the local network
        /// </summary>
        /// <returns>List of strings</returns>
        public List<string> GetSQLServers()
        {
            var servers = SmoApplication.EnumAvailableSqlServers();
            if ( servers.Rows.Count == 0) return null;
            var list =
                from s in servers.AsEnumerable()
                select s.Field<string>("Name");
            return list.ToList();
        }

        #endregion
    }
}
